------------------------------------------------------------------------------------------------------------------------------------ name: log: C:\Projects\Analysis\Calendar tutorial\Stata\Example2.log log type: text opened on: 31 Aug 2017, 00:30:08 . * DHS Calendar Tutorial - Example 2 . * Last pregnancy, duration of pregnancy and method used before pregnancy . . * download the model dataset for individual women's recode: "ZZIR62FL.DTA" . * the model datasets are available at http://dhsprogram.com/data/download-model-datasets.cfm . . * change to a working directory where the data are stored . * or add the full path to the 'use' command below . cd "C:\Data\DHS_model" C:\Data\DHS_model . . * open the dataset to use, selecting just the variables we are going to use . use vcal_1 v000 v005 v007 v008 v017 v018 v019 v208 b3_01 using "ZZIR62FL.DTA", clear . . . * Example 2A . * ----------------------- . * get century month code (CMC) of date of last birth or pregnancy from calendar . * using string functions . . . * Step 2.1 . * length of full calendar string including leading blanks (80) . * actual length used according to v019 will be less . egen vcal_len = max(strlen(vcal_1)) . * most calendars are 80 in length, but those without method use may be short, so use the max . label variable vcal_len "Length of calendar" . . . * Step 2.2 . * position of last birth or terminated pregnancy in calendar . gen lb = strpos(vcal_1,"B") . gen lp = strpos(vcal_1,"T") . * update lp with position of last birth if there was no terminated pregnancy, . * or if the last birth was more recent than last terminated pregnancy . replace lp = lb if lp == 0 | (lb > 0 & lb < lp) (4,428 real changes made) . * e.g. if calendar is as below ("_" used to replace blank for display here): . * ______________00000BPPPPPPPP000000555555500000TPP00000000000000BPPPPPPPP00000000 . * ^ . * lp would be 20 . label variable lp "Position of last birth or terminated pregnancy in calendar" . label def lp 0 "No birth or terminated pregnancy in calendar" . label value lp lp . . * get the type of birth or terminated pregnancy . * lp_type will be set to 1 if lp refers to a birth, . * and 2 if lp refers to a terminated pregnancy using the position in "BT" for the resulting code . gen lp_type = strpos("BT",substr(vcal_1,lp,1)) if lp > 0 (3,657 missing values generated) . label variable lp_type "Birth or terminated pregnancy in calendar" . label def lp_type 1 "Birth" 2 "Terminated pregnancy" . label value lp_type lp_type . . list vcal_1 lp lp_type in 1/5 +----------------------------------------------------------------------------------+ 1. | vcal_1 | | 00000BPPPPPPPP00000000000000000000000BPPPPPPPP00000000000000000000 | |----------------------------------------------------------------------------------| | lp | lp_type | | 20 | Birth | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 2. | vcal_1 | | PPPPPP000000000000000000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | lp_type | | 45 | Birth | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 3. | vcal_1 | | 000000000000000000000000000000000000000000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | lp_type | | No birth or terminated pregnancy in calendar | . | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 4. | vcal_1 | | 0000000000BPPPPPPPP00000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | lp_type | | 25 | Birth | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 5. | vcal_1 | | 0BPPPPPPPP000000000000000000000000BPPPPPPPP00000000000000000000000 | |----------------------------------------------------------------------------------| | lp | lp_type | | 16 | Birth | +----------------------------------------------------------------------------------+ . tab lp lp_type, m Position of last | Birth or terminated pregnancy in birth or terminated | calendar pregnancy in calendar | Birth Terminate . | Total ----------------------+---------------------------------+---------- No birth or terminate | 0 0 3,657 | 3,657 11 | 1 0 0 | 1 12 | 15 0 0 | 15 13 | 36 3 0 | 39 14 | 59 5 0 | 64 15 | 105 14 0 | 119 16 | 112 3 0 | 115 17 | 115 14 0 | 129 18 | 117 9 0 | 126 19 | 115 8 0 | 123 20 | 135 4 0 | 139 21 | 97 10 0 | 107 22 | 92 3 0 | 95 23 | 108 9 0 | 117 24 | 93 7 0 | 100 25 | 88 9 0 | 97 26 | 122 5 0 | 127 27 | 123 3 0 | 126 28 | 110 7 0 | 117 29 | 106 8 0 | 114 30 | 106 11 0 | 117 31 | 95 5 0 | 100 32 | 101 6 0 | 107 33 | 72 4 0 | 76 34 | 55 2 0 | 57 35 | 68 1 0 | 69 36 | 55 4 0 | 59 37 | 73 5 0 | 78 38 | 97 2 0 | 99 39 | 99 4 0 | 103 40 | 99 1 0 | 100 41 | 103 6 0 | 109 42 | 85 10 0 | 95 43 | 62 2 0 | 64 44 | 56 2 0 | 58 45 | 53 4 0 | 57 46 | 40 0 0 | 40 47 | 41 2 0 | 43 48 | 47 3 0 | 50 49 | 64 6 0 | 70 50 | 65 2 0 | 67 51 | 76 4 0 | 80 52 | 73 9 0 | 82 53 | 81 1 0 | 82 54 | 71 3 0 | 74 55 | 38 0 0 | 38 56 | 46 0 0 | 46 57 | 33 2 0 | 35 58 | 23 3 0 | 26 59 | 20 1 0 | 21 60 | 37 1 0 | 38 61 | 34 3 0 | 37 62 | 30 1 0 | 31 63 | 39 2 0 | 41 64 | 47 1 0 | 48 65 | 62 8 0 | 70 66 | 46 5 0 | 51 67 | 25 2 0 | 27 68 | 26 1 0 | 27 69 | 22 2 0 | 24 70 | 25 0 0 | 25 71 | 14 2 0 | 16 72 | 19 0 0 | 19 73 | 30 1 0 | 31 74 | 26 3 0 | 29 75 | 38 0 0 | 38 76 | 55 1 0 | 56 77 | 34 1 0 | 35 78 | 30 2 0 | 32 79 | 18 0 0 | 18 80 | 25 1 0 | 26 ----------------------+---------------------------------+---------- Total | 4,428 263 3,657 | 8,348 . . . * Step 2.3 . * if there is a birth or terminated pregnancy in the calendar then calculate CMC . * of date of last birth or pregnancy by adding length of calendar to start CMC . * less the position of the birth or pregnancy . * calendar starts in CMC given in v017 . * lp > 0 means there was a birth or terminated pregnancy in the calendar . gen cmc_lp = v017 + vcal_len - lp if lp > 0 (3,657 missing values generated) . label variable cmc_lp "Century month code of last pregnancy" . * e.g. if calendar is as below and cmc of beginning of calendar (V017) = 1321: . * ______________00000BPPPPPPPP000000555555500000TPP00000000000000BPPPPPPPP00000000 . * cmc_lp would be 1381, calculation as follows: . * 1321 + 80 - 20 (80 is the vcal_len, and 20 is the position of lp) . list v017 lp vcal_len cmc_lp in 1/5 +-------------------------------------------------------------------------+ | v017 lp vcal_len cmc_lp | |-------------------------------------------------------------------------| 1. | 1321 20 80 1381 | 2. | 1321 45 80 1356 | 3. | 1321 No birth or terminated pregnancy in calendar 80 . | 4. | 1321 25 80 1376 | 5. | 1321 16 80 1385 | +-------------------------------------------------------------------------+ . . * check the variables created. . tab lp Position of last birth or terminated | pregnancy in calendar | Freq. Percent Cum. ----------------------------------------+----------------------------------- No birth or terminated pregnancy in cal | 3,657 43.81 43.81 11 | 1 0.01 43.82 12 | 15 0.18 44.00 13 | 39 0.47 44.47 14 | 64 0.77 45.23 15 | 119 1.43 46.66 16 | 115 1.38 48.04 17 | 129 1.55 49.58 18 | 126 1.51 51.09 19 | 123 1.47 52.56 20 | 139 1.67 54.23 21 | 107 1.28 55.51 22 | 95 1.14 56.65 23 | 117 1.40 58.05 24 | 100 1.20 59.25 25 | 97 1.16 60.41 26 | 127 1.52 61.93 27 | 126 1.51 63.44 28 | 117 1.40 64.84 29 | 114 1.37 66.21 30 | 117 1.40 67.61 31 | 100 1.20 68.81 32 | 107 1.28 70.09 33 | 76 0.91 71.00 34 | 57 0.68 71.68 35 | 69 0.83 72.51 36 | 59 0.71 73.22 37 | 78 0.93 74.15 38 | 99 1.19 75.34 39 | 103 1.23 76.57 40 | 100 1.20 77.77 41 | 109 1.31 79.07 42 | 95 1.14 80.21 43 | 64 0.77 80.98 44 | 58 0.69 81.67 45 | 57 0.68 82.36 46 | 40 0.48 82.83 47 | 43 0.52 83.35 48 | 50 0.60 83.95 49 | 70 0.84 84.79 50 | 67 0.80 85.59 51 | 80 0.96 86.55 52 | 82 0.98 87.53 53 | 82 0.98 88.51 54 | 74 0.89 89.40 55 | 38 0.46 89.85 56 | 46 0.55 90.40 57 | 35 0.42 90.82 58 | 26 0.31 91.14 59 | 21 0.25 91.39 60 | 38 0.46 91.84 61 | 37 0.44 92.29 62 | 31 0.37 92.66 63 | 41 0.49 93.15 64 | 48 0.57 93.72 65 | 70 0.84 94.56 66 | 51 0.61 95.17 67 | 27 0.32 95.50 68 | 27 0.32 95.82 69 | 24 0.29 96.11 70 | 25 0.30 96.41 71 | 16 0.19 96.60 72 | 19 0.23 96.83 73 | 31 0.37 97.20 74 | 29 0.35 97.54 75 | 38 0.46 98.00 76 | 56 0.67 98.67 77 | 35 0.42 99.09 78 | 32 0.38 99.47 79 | 18 0.22 99.69 80 | 26 0.31 100.00 ----------------------------------------+----------------------------------- Total | 8,348 100.00 . tab cmc_lp Century | month code | of last | pregnancy | Freq. Percent Cum. ------------+----------------------------------- 1321 | 26 0.55 0.55 1322 | 18 0.38 0.94 1323 | 32 0.68 1.62 1324 | 35 0.75 2.37 1325 | 56 1.19 3.56 1326 | 38 0.81 4.37 1327 | 29 0.62 4.99 1328 | 31 0.66 5.65 1329 | 19 0.41 6.05 1330 | 16 0.34 6.40 1331 | 25 0.53 6.93 1332 | 24 0.51 7.44 1333 | 27 0.58 8.02 1334 | 27 0.58 8.59 1335 | 51 1.09 9.68 1336 | 70 1.49 11.17 1337 | 48 1.02 12.19 1338 | 41 0.87 13.07 1339 | 31 0.66 13.73 1340 | 37 0.79 14.52 1341 | 38 0.81 15.33 1342 | 21 0.45 15.77 1343 | 26 0.55 16.33 1344 | 35 0.75 17.08 1345 | 46 0.98 18.06 1346 | 38 0.81 18.87 1347 | 74 1.58 20.44 1348 | 82 1.75 22.19 1349 | 82 1.75 23.94 1350 | 80 1.71 25.64 1351 | 67 1.43 27.07 1352 | 70 1.49 28.57 1353 | 50 1.07 29.63 1354 | 43 0.92 30.55 1355 | 40 0.85 31.40 1356 | 57 1.22 32.62 1357 | 58 1.24 33.85 1358 | 64 1.36 35.22 1359 | 95 2.03 37.24 1360 | 109 2.32 39.57 1361 | 100 2.13 41.70 1362 | 103 2.20 43.89 1363 | 99 2.11 46.00 1364 | 78 1.66 47.67 1365 | 59 1.26 48.92 1366 | 69 1.47 50.39 1367 | 57 1.22 51.61 1368 | 76 1.62 53.23 1369 | 107 2.28 55.51 1370 | 100 2.13 57.64 1371 | 117 2.49 60.14 1372 | 114 2.43 62.57 1373 | 117 2.49 65.06 1374 | 126 2.69 67.75 1375 | 127 2.71 70.45 1376 | 97 2.07 72.52 1377 | 100 2.13 74.65 1378 | 117 2.49 77.15 1379 | 95 2.03 79.17 1380 | 107 2.28 81.45 1381 | 139 2.96 84.42 1382 | 123 2.62 87.04 1383 | 126 2.69 89.73 1384 | 129 2.75 92.47 1385 | 115 2.45 94.93 1386 | 119 2.54 97.46 1387 | 64 1.36 98.83 1388 | 39 0.83 99.66 1389 | 15 0.32 99.98 1390 | 1 0.02 100.00 ------------+----------------------------------- Total | 4,691 100.00 . . * list cases where cmc_lp and b3_01 don't agree if the last pregnancy was a birth . list cmc_lp b3_01 if lp > 0 & lp == lb & cmc_lp != b3_01 . * there shouldn't be any cases listed. . . . * Example 2B . * ----------------------- . * Find the duration of the pregnancy for the last birth or terminated pregnancy. . * (continues from Example 2A) . . . * Step 2.4 . * get the duration of pregnancy and the position of the month prior to the pregnancy . * start from the position after the birth in the calendar string by creating a substring . * indexnot searches the substring for the first position that is not a "P" (pregnancy) . * piece is the piece of the calendar before the birth ("B") or termination ("T") code . gen piece = substr(vcal_1, lp+1, vcal_len-lp) (26 missing values generated) . * find the length of the pregnancy . gen dur_preg = indexnot(piece, "P") if lp > 0 (3,657 missing values generated) . * dur_preg will be 0 if pregnant at the start of the calendar . label variable dur_preg "Duration of pregnancy" . * e.g. if calendar is as below: . * ______________00000BPPPPPPPP000000555555500000TPP00000000000000BPPPPPPPP00000000 . * |12345678^ . * dur_preg would be 9 for the last pregnancy (1 B plus 8 Ps) . * if we find something other than a "P" then that is the month before the pregnancy . * if it returns 0 then the pregnancy is underway in the first month of the calendar . . * now get the position in the calendar to reflect the full calendar . * not just the piece before the birth, by adding lp . * _bp means 'before pregnancy'. pos_bp means position before pregnancy . gen pos_bp = dur_preg + lp if dur_preg > 0 (3,939 missing values generated) . label variable pos_bp "Position before pregnancy" . label def pos_bp 0 "Pregnant in first month of calendar" . label val pos_bp pos_bp . * e.g. if calendar is as below: . * ______________00000BPPPPPPPP000000555555500000TPP00000000000000BPPPPPPPP00000000 . * ^ . * pos_bp would be 29 . list vcal_1 lp dur_preg pos_bp in 1/5 +----------------------------------------------------------------------------------+ 1. | vcal_1 | | 00000BPPPPPPPP00000000000000000000000BPPPPPPPP00000000000000000000 | |----------------------------------------------------------------------------------| | lp | dur_preg | pos_bp | | 20 | 9 | 29 | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 2. | vcal_1 | | PPPPPP000000000000000000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | dur_preg | pos_bp | | 45 | 9 | 54 | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 3. | vcal_1 | | 000000000000000000000000000000000000000000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | dur_preg | pos_bp | | No birth or terminated pregnancy in calendar | . | . | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 4. | vcal_1 | | 0000000000BPPPPPPPP00000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------| | lp | dur_preg | pos_bp | | 25 | 9 | 34 | +----------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------+ 5. | vcal_1 | | 0BPPPPPPPP000000000000000000000000BPPPPPPPP00000000000000000000000 | |----------------------------------------------------------------------------------| | lp | dur_preg | pos_bp | | 16 | 9 | 25 | +----------------------------------------------------------------------------------+ . tab dur_preg lp_type, m Duration | Birth or terminated pregnancy in of | calendar pregnancy | Birth Terminate . | Total -----------+---------------------------------+---------- 0 | 277 5 0 | 282 1 | 0 9 0 | 9 2 | 0 43 0 | 43 3 | 0 75 0 | 75 4 | 0 61 0 | 61 5 | 0 29 0 | 29 6 | 0 15 0 | 15 7 | 1 6 0 | 7 8 | 70 10 0 | 80 9 | 3,496 10 0 | 3,506 10 | 572 0 0 | 572 11 | 12 0 0 | 12 . | 0 0 3,657 | 3,657 -----------+---------------------------------+---------- Total | 4,428 263 3,657 | 8,348 . . . * Example 2C . * ----------------------- . * Find last method used before pregnancy, but after any other pregnancy in the last 5 year . * (continues from Example 2B) . . . * Step 2.5 . * find the last code that is not 0 before the pregnancy (using indexnot), . * searching in a substring of the calendar from the month before pregnancy and earlier, . * but not more than 5 years back . * lnz means 'last non-zero before the pregnancy' . gen lnz = indexnot(substr(vcal_1, pos_bp, vcal_len - pos_bp + 1),"0") /// > if inrange(pos_bp, 1, vcal_len) (3,939 missing values generated) . * get the actual position in the calendar of the last non-zero before the last birth . gen pos_lnz = pos_bp + lnz - 1 if inrange(lnz, 1, vcal_len) (6,083 missing values generated) . * if last non-zero is more than 5 years before interview, set position to 0 . replace pos_lnz = 0 if lnz == 0 | (pos_lnz != . & pos_lnz > v018+59) (2,578 real changes made) . label variable pos_lnz "Position in calendar of last non-zero before pregnancy" . label def pos_lnz 0 "No non-zero preceding the pregnancy in the last 5 years" . label val pos_lnz pos_lnz . . * list a few cases to check . list vcal_1 lp pos_bp pos_lnz in 1/5 +-----------------------------------------------------------------------------------------------------------------+ 1. | vcal_1 | | 00000BPPPPPPPP00000000000000000000000BPPPPPPPP00000000000000000000 | |-----------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | | 20 | 29 | 52 | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ 2. | vcal_1 | | PPPPPP000000000000000000000000BPPPPPPPP000000000000000000000000000 | |-----------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | | 45 | 54 | No non-zero preceding the pregnancy in the last 5 years | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ 3. | vcal_1 | | 000000000000000000000000000000000000000000000000000000000000000000 | |-----------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | | No birth or terminated pregnancy in calendar | . | . | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ 4. | vcal_1 | | 0000000000BPPPPPPPP00000000000BPPPPPPPP000000000000000000000000000 | |-----------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | | 25 | 34 | 45 | +-----------------------------------------------------------------------------------------------------------------+ +-----------------------------------------------------------------------------------------------------------------+ 5. | vcal_1 | | 0BPPPPPPPP000000000000000000000000BPPPPPPPP00000000000000000000000 | |-----------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | | 16 | 25 | 49 | +-----------------------------------------------------------------------------------------------------------------+ . . . * Step 2.6 . * check if the respondent is using a method before the pregnancy but in the last 5 years . gen code_lnz = substr(vcal_1, pos_lnz, 1) if inrange(pos_lnz, v018, v018+59) (6,517 missing values generated) . replace code_lnz = "0" if pos_lnz == 0 (2,578 real changes made) . . * if the code is NOT(!) a zero ("0"), a "B", "P" or "T" then the respondent was using a method . gen used_bp = !inlist(code_lnz, "0","B","P","T") if code_lnz != "" (3,939 missing values generated) . label variable code_lnz "Last non-zero code before pregnancy" . label variable used_bp "Using a method before the last pregnancy" . label def used_bp 0 "No" 1 "Yes" . label val used_bp used_bp . . * list a few cases to check . list vcal_1 lp pos_bp pos_lnz code_lnz used_bp in 1/5 +----------------------------------------------------------------------------------------------------------------------------+ 1. | vcal_1 | | 00000BPPPPPPPP00000000000000000000000BPPPPPPPP00000000000000000000 | |----------------------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | code_lnz | | 20 | 29 | 52 | B | |----------------------------------------------------------------------------------------------------------------------------| | used_bp | | No | +----------------------------------------------------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------------------------------------------------+ 2. | vcal_1 | | PPPPPP000000000000000000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | code_lnz | | 45 | 54 | No non-zero preceding the pregnancy in the last 5 years | 0 | |----------------------------------------------------------------------------------------------------------------------------| | used_bp | | No | +----------------------------------------------------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------------------------------------------------+ 3. | vcal_1 | | 000000000000000000000000000000000000000000000000000000000000000000 | |----------------------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | code_lnz | | No birth or terminated pregnancy in calendar | . | . | | |----------------------------------------------------------------------------------------------------------------------------| | used_bp | | . | +----------------------------------------------------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------------------------------------------------+ 4. | vcal_1 | | 0000000000BPPPPPPPP00000000000BPPPPPPPP000000000000000000000000000 | |----------------------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | code_lnz | | 25 | 34 | 45 | B | |----------------------------------------------------------------------------------------------------------------------------| | used_bp | | No | +----------------------------------------------------------------------------------------------------------------------------+ +----------------------------------------------------------------------------------------------------------------------------+ 5. | vcal_1 | | 0BPPPPPPPP000000000000000000000000BPPPPPPPP00000000000000000000000 | |----------------------------------------------------------------------------------------------------------------------------| | lp | pos_bp | pos_lnz | code_lnz | | 16 | 25 | 49 | B | |----------------------------------------------------------------------------------------------------------------------------| | used_bp | | No | +----------------------------------------------------------------------------------------------------------------------------+ . . . * Step 2.7 . * last method used before pregnancy, but may have been followed by a period of non-use . * converting the string variable to numeric, although it isn't really necessary for most analyses . . * set up a list of codes used in the calendar, with each position matching the coding in V312 . * use a tilde (~) to mark gaps in the coding that are not used for this survey . * e.g. Emergency contraception and Standard days method do not exist in this calendar . * note that some of the codes are survey specific so this list may need adjusting . scalar methodlist = "123456789WNALCF~M~" . gen method_bp = strpos(methodlist,code_lnz) if code_lnz != "" (3,939 missing values generated) . * convert the missing code to 99 . replace method_bp = 99 if code_lnz == "?" (0 real changes made) . * now check if there are any method codes that were not converted, and change these to -1 . replace method_bp = -1 if method_bp == 0 & used_bp == 1 (0 real changes made) . . * alternatively, . * use the do file below to set up survey specific coding using scalar methodlist and label method . * and recode the method and/or reasons for discontinuation . * include the path to the do file if needed . *run "Calendar recoding.do" code_lnz method_bp . * and skip the value labeling in step 2.8 as the do file above includes the value labeling . . * if no method was used, set method_bp to 0 . replace method_bp = 0 if used_bp == 0 (0 real changes made) . . . * Step 2.8 . * label the method variable and codes . label variable method_bp "Method used before the last pregnancy (numeric)" . label def method /// > 0 "No method used" /// > 1 "Pill" /// > 2 "IUD" /// > 3 "Injectable" /// > 4 "Diaphragm" /// > 5 "Condom" /// > 6 "Female sterilization" /// > 7 "Male sterilization" /// > 8 "Periodic abstinence/Rhythm" /// > 9 "Withdrawal" /// > 10 "Other traditional method" /// > 11 "Norplant" /// > 12 "Abstinence" /// > 13 "Lactational amenorrhea method" /// > 14 "Female condom" /// > 15 "Foam and Jelly" /// > 16 "Emergency contraception" /// > 17 "Other modern method" /// > 18 "Standard days method" /// > 99 "Missing" /// > -1 "***Unknown code not recoded***" . . label val method_bp method . tab method_bp Method used before the last | pregnancy (numeric) | Freq. Percent Cum. -------------------------------+----------------------------------- No method used | 4,090 92.76 92.76 Pill | 117 2.65 95.42 IUD | 4 0.09 95.51 Injectable | 122 2.77 98.28 Condom | 8 0.18 98.46 Periodic abstinence/Rhythm | 3 0.07 98.53 Withdrawal | 1 0.02 98.55 Other traditional method | 14 0.32 98.87 Norplant | 17 0.39 99.25 Lactational amenorrhea method | 33 0.75 100.00 -------------------------------+----------------------------------- Total | 4,409 100.00 . . * list all cases in the first 500 that used before the pregnancy . * anytime in the 5 years before interview . list vcal_1 lp pos_lnz code_lnz method_bp if used_bp==1 in 1/500 +-------------------------------------------------------------------------------------------------------------------------+ | vcal_1 lp pos_lnz code_lnz method_bp | |-------------------------------------------------------------------------------------------------------------------------| 35. | 1111111000000000000000000BPPPPPPPP001111111111111000000000000000000 39 50 1 Pill | 254. | 3333333333333111111111111111110000000000000000BPPPPPPPP00001111111 61 74 1 Pill | 257. | 11TPPP11111111111111111111111111111111111111111111111110000000BPPP 17 21 1 Pill | 265. | 000000000000BPPPPPPPP000333333333333333330000000000BPPPPPPPP00000000 25 37 3 Injectable | 283. | 00BPPPPPPPPP000NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN000000000000000 15 28 N Norplant | |-------------------------------------------------------------------------------------------------------------------------| 285. | NNN0000000000000000000000000000BPPPPPPPPP000011111111111111111111111 44 58 1 Pill | 290. | 0000000BPPPPPPPP0033333333333333330000000000000000000000000000000000 20 31 3 Injectable | 310. | 000000000BPPPPPPPPP00111111111111111111111111111111111111110000000000 21 33 1 Pill | 359. | 3333300TPPPPPP0000111111110BPPPPPPPP0000000000000000000000000000000 21 32 1 Pill | 394. | 0000000000000000BPPPPPPPP00000000000033333333333333333333333333333 31 52 3 Injectable | |-------------------------------------------------------------------------------------------------------------------------| 409. | 00000000BPPPPPPPP033333333333333333333300000000000000000000BPPPPPP 23 33 3 Injectable | 416. | 00000000000000BPPPPPPPP1111111111110000000000000000BPPPPPPPP000000 29 38 1 Pill | 426. | 00BPPPPPPPP11111111111NNNNNNNNNNNNNNNNNNNNNNNNN0000000000000000000 17 26 1 Pill | 428. | 00000BPPPPPPPPPPNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN 20 31 N Norplant | 429. | 0000000000BPPPPPPPP0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN000000BPPP 25 35 N Norplant | +-------------------------------------------------------------------------------------------------------------------------+ . . . * Step 2.9 . * compute the weight variable and weight the data. . gen wt = v005/1000000 . * tab the last method used prior to the pregnancy by the type of pregnancy outcome . tab method_bp lp_type [iw=wt], col +-------------------+ | Key | |-------------------| | frequency | | column percentage | +-------------------+ Method used before | Birth or terminated the last pregnancy | pregnancy in calendar (numeric) | Birth Terminate | Total ----------------------+----------------------+---------- No method used | 3,726.587 227.25559 |3,953.8428 | 91.71 84.24 | 91.24 ----------------------+----------------------+---------- Pill | 116.92239 17.927922 | 134.85031 | 2.88 6.65 | 3.11 ----------------------+----------------------+---------- IUD |3.08249402 .206567 | 3.289061 | 0.08 0.08 | 0.08 ----------------------+----------------------+---------- Injectable | 140.84152 14.973971 | 155.81549 | 3.47 5.55 | 3.60 ----------------------+----------------------+---------- Condom | 8.8306651 4.903457 |13.7341221 | 0.22 1.82 | 0.32 ----------------------+----------------------+---------- Periodic abstinence/R | 3.022521 0 | 3.022521 | 0.07 0.00 | 0.07 ----------------------+----------------------+---------- Withdrawal | .80930901 0 | .80930901 | 0.02 0.00 | 0.02 ----------------------+----------------------+---------- Other traditional met |13.7197451 .69064802 | 14.410393 | 0.34 0.26 | 0.33 ----------------------+----------------------+---------- Norplant | 21.725411 1.271946 | 22.997357 | 0.53 0.47 | 0.53 ----------------------+----------------------+---------- Lactational amenorrhe | 27.987985 2.548405 | 30.53639 | 0.69 0.94 | 0.70 ----------------------+----------------------+---------- Total | 4,063.529 269.77851 | 4,333.308 | 100.00 100.00 | 100.00 . end of do-file name: log: C:\Projects\Analysis\Calendar tutorial\Stata\Example2.log log type: text closed on: 31 Aug 2017, 00:30:08 ------------------------------------------------------------------------------------------------------------------------------------